package com.ares.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ares.service.util.Constantes;
import com.ares.service.util.Util;


/**
 * Servlet implementation class servletTimeOut
 */
public class servletTimeOut extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public servletTimeOut() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 PrintWriter out = response.getWriter();
		 HttpSession session = request.getSession();
		 Date fechaMenor =  new Date(session.getLastAccessedTime());
		 System.out.println("fechaMenor: " + fechaMenor);
	        out.println(fechaMenor);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 response.setContentType("text/html;charset=UTF-8");
		 String estado = request.getParameter("estado");
	        PrintWriter out = response.getWriter();
	        HttpSession session = request.getSession();
	        
	        if (estado.equals("activo")) {
	        	session.setMaxInactiveInterval(session.getMaxInactiveInterval());
	        	System.out.println("activo " + session.getMaxInactiveInterval());
	        	out.println("activo");
			} else if(estado.equals("inactivo")){
				System.out.println("Dead");
				out.println("inactivo");
				session.invalidate();
			}
	        
}

	
}
